#include "movieDetailResMessage.h"
#include "jsonUtils.h"

MovieDetailResMessage::MovieDetailResMessage(MtpProtocol* packet) : MtpMessage(packet),res(false),movie(NULL)
{

}

MovieDetailResMessage::MovieDetailResMessage(Movie* movie, const MtpMessage* src) 
	: MtpMessage(new MtpProtocol(L"movieDetailRes", (const MtpProtocol*)src->getPacket())),res(true),movie(movie)
{

}

void MovieDetailResMessage::encodeBody()
{
	JsonDoc& doc = res.jsonSerialize();
	if (movie != NULL) {
		JsonValue v(rapidjson::kObjectType);
		movie->toDetailJson(v, doc.GetAllocator());
		doc.AddMember(L"data", v, doc.GetAllocator());
	}
	jsonContent = JsonUtils::jsonStr(doc);
	MtpMessage::encodeBody();
}
